package com.xuhuan.algorithm.demo2;

import java.util.Arrays;

/**
 * @author huan.xu
 * @ClassName Demo2Code
 * @date 2021/4/22 16:22
 * @Description 冒泡排序
 */
public class Demo2Code {

    public static void main(String[] args) {
        int[] nums = {5, 1, 9, 2, 6, 0, 4, 3, 8, 7};
        System.out.println("排序前：" + Arrays.toString(nums));

        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - i - 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int temp;
                    temp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
        }
        System.out.println("排序后：" + Arrays.toString(nums));
    }
}
